package handlers

import (
	"context"
	"github.com/gin-gonic/gin"
	log "github.com/sirupsen/logrus"
	"github.com/twwch/gin-sdk/handler"
	"github.com/twwch/gin-sdk/server"
	"net/http"
	authSvc "twwch/k8s-admin/application/auth"
	"twwch/k8s-admin/models/auth"
)

type AuthHandler struct {
	handler.Base
	authSvc *authSvc.AuthService
}

func (h *AuthHandler) Init(ginRouter *gin.RouterGroup) {
	h.Logger = log.WithField("handler", "auth")
	h.authSvc = authSvc.GetService()
	// registry http handler
	if ginRouter != nil {
		appGroup := ginRouter.Group("/auth")
		server.Route(appGroup, http.MethodPost, "/token", h.Token)
	}
}

func (h *AuthHandler) Token(ctx context.Context, req *auth.TokenReq) (*auth.TokenResp, error) {
	return h.authSvc.Token(ctx, req)
}
